
int Binarysize(struct TreeNode* root)
{
    if (root == NULL)
        return 0;
    return Binarysize(root->left) + Binarysize(root->right) + 1;
}

void BinaryPreorder(struct TreeNode* root, int* ret, int* pi)
{
    if (root == NULL)
        return;
    ret[(*pi)++] = root->val;
    BinaryPreorder(root->left, ret, pi);
    BinaryPreorder(root->right, ret, pi);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize) {
    *returnSize = Binarysize(root);
    int* ret = (int*)malloc(sizeof(int) * (*returnSize));
    int i = 0;
    BinaryPreorder(root, ret, &i);
    return ret;
}